// pages/integral-mall/happyland/happyland.js
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods_list: [],
    catId: '',
    is_distributor: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log(e)
    page = 1, this.getGoodsList(e.catId);
    var a = this
    a.setData({
      catId: e.catId,
      is_distributor: e.is_distributor
    })
    wx.setNavigationBarTitle({
      title: e.name
    })
  },

  getGoodsList: function (t) {
    var a = this;
    console.log('aaaaaaaa', t)
    getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.integral.goods_list,
      data: {
        page: page,
        cat_id: t
      },
      success: function (t) {
        if (0 === t.code) {
          var e = a.data.goods_list;
          0 < t.data.list.length && (0 < e.length && (e = e.concat(t.data.list)), 0 === e.length && (e = t.data.list),
            page += 1), 0 === t.data.list.length && getApp().core.showToast({
              title: "没有更多啦",
              icon: "none"
            }), a.setData({
              goods_list: e,
            })
        }
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  goodsInfo: function (t) {
    var e = t.currentTarget.dataset.goodsId;
    var goods_num = t.currentTarget.dataset.goods_num;
    if (goods_num == 0) {
      getApp().core.showToast({
        title: "此商品已售罄",
        icon: "none"
      })
    } else {
      getApp().core.navigateTo({
        url: "/pages/integral-mall/goods-info/index?goods_id=" + e
      });
    }
  },
  onReachBottom: function (t) {
    var a = this
    getApp().page.onReachBottom(this);
    this.getGoodsList(a.data.catId);
  },
})